package lab03.test03;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class Test {
    public static void main(String[] args) {

        //字节流写文件

        String path="F:\\test.txt";
        String value="beijing欢迎你!";
        String values="我的学号是：你自己的学号";

        FileOutputStream fileOutputStream=null;

        try {
           fileOutputStream=new FileOutputStream(path);

            fileOutputStream.write(value.getBytes());
            fileOutputStream.write(values.getBytes());

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                fileOutputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }



        //字节流读文件
        FileInputStream fileInputStream=null;
        try {
            fileInputStream=new FileInputStream(path);

            int tmp;
            //一次读一个字节
            while((tmp=fileInputStream.read())!=-1){
                System.out.print((char)tmp);
            }

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                fileInputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }



    }
}
